package com.solidsnake.scala.http

import scala.collection.mutable
import java.util.Date
import java.text.SimpleDateFormat
import java.nio.charset.Charset
import java.awt.Image
import javax.imageio.ImageIO
import java.io.{File, FileOutputStream, OutputStream, InputStream}
import javax.imageio.stream.ImageInputStreamImpl
import com.solidsnake.scala.image.{CalculateImageDataManager, ImageManage}
import java.net.URLEncoder


/**
 * Created with IntelliJ IDEA.
 * User: solidsnake
 * Date: 13-11-6
 * Time: 上午11:20
 * To change this template use File | Settings | File Templates.
 */
object sb {
  def main(s : Array[String]) : Unit = {


//    val dateStr = this.getNowDate
//    val header = Map(HttpHandlerField.REFERER -> "http://app02.szaic.gov.cn/WERMIS2.WebUI/Default.aspx")
//    val result = HttpUtils.getImage(
//      "http://app02.szaic.gov.cn/WERMIS2.WebUI/webpages/webreguser/checkcode.aspx",
//      Map("code" -> dateStr), Charset.forName("UTF-8"), header, true)
//    val results = StringBuilder.newBuilder
//    for ((k, v) <- result._1) {
//      if(k != null) {
//        results append k + ":"
//      }
//      v.foreach(value => {
//        results append value
//      })
//      results append "\n"
//    }
//    println(results)
//
//    // 其实加了HTML 也能生成完整的图片。
//    new FileOutputStream(new File("/home/solidsnake/桌面/abc/sb.gif")).write(result._3)
//
//    val sss = CalculateImageDataManager.readVerificationCode("/home/solidsnake/桌面/abc/sb.gif")
//    println(sss)
    //"__VIEWSTATE" -> "HeYdR1BGwG+7N2OsgADGDWvcwJCotJ15zoKKmRyV42AkrzFNs5Ma1I3Vl6ZBRHiRy2RUNm1iV7k0HfMHc+mZayxWuqx0VXGI7RbBRzGQ7j47fnfDQlz8ekHFaO5DMkYqouuOBH80LmUP1B4LI9In60Fpz4uDr1cXVFQAcuTPtMLE7R2Ay6YV75HCFtkrMV2v3hHMZPNLzwL79njn/XmyD6SyXAC0Vzfe16UnTP7PIMLQHZTVXu4U1jphxtLeYqC0ILI5f6Uf6zFs2Slej5scSIiP+cgC68YS8FB45siOzmfLfnapTwatrG52QicGtVESaF4lEwgCgmXA4wXHeNWC5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x/TTnSOiIaoN0dDy8dXjytKcm7IGnzS96UgbdKdugmbsOluagXZkqCx7TKE8oc98CVvbniQU74Gf3jWb7TBkR59BkXncFwxP8oqcwm/gNySDgrj3ILqNM2Ls38WoMKJ19cwalp8WeytAeT3/Wah1J3vAxMQxlEczYpPf3x/XbuKYKd7A7H9ou141Q+vsZkicusCHeXBgAcsHIt/+B1FOLAL9SNKnIrIi1C2HY8gDy8O4IkcSikIOtlaBIrGJz3Vhiatl1HVRyy0/+3h6YaJE1qQcQG3KiQL1F4Ba6wH+g67ftQB75BgG3m6dqE3jPxqypNwfbSXQTJbVTUvQ9hzB5eOn9EOAgVAttxXB51y2wvSPxFmbyh7ZG056O/e25kDEC7rODwRFhxx/tr3bBjPvAFw1mPgubH0cz/5Uvrzdes/0r+czQY350NeoTZsE1BGkWsnhAZLcvvMN7/AV4r6IEa9wJU2d8/1vU3QFPOaFlKyj7tVvIetIZ0w+6/ijpydjrGhQ9sKD5t8D9utCeGZKAtsBrlEDHHR//sAR/2bDCzfzPS1A7fG2+dzEnJkUWRMBny+EdP8ASPjjS169T/IPMW0B0OCx8NVOcMEsaJMA6XKemu5n+iWc/Z4hs9tzGURVmHSoqYxdg4ONGCfOoVbr90RgiUX1+YkTWbnfBLNAcPcOW7mE9cWoIyb9JyftiNFK7YAzcOzgAuGVoR/a8cB3RMs23DqjTP/YKsofkIslI09Ve0a67+syvg/lFESBfYLAVKY1fgnDcEH83kfdMFzOfWk1iVXxdkj40CnKC582sYNpnqo1OLxrHcgfUh+QS0av5lIbmIH3osCm91J7e2eG4v7x2FKq7YKKYhet4Wyo6a7JXgERSWTrLluWrhWiqjwrgORz2DhIi3UglRcl2xE9EeJEYjnqIxLqebfacPOq0vy9TQJ55DvfsWrC/8QnWXzQyAR3vztYceL/gBc4FVHErJXbCQIcvIw1pKGUqUI9ts0="
    val params =  Map(

      "__EVENTTARGET" -> "",
      "__EVENTARGUMENT" -> "",
      "__LASTFOCUS" -> "",
      "__VIEWSTATE" -> sv,
      "NameCenter" -> "no",
      "SSDJNCREnterPage1$rblHadTradeNameProof" -> "0",
      "SSDJNCREnterPage1$rblBigEntType" -> "0",
      "SSDJNCREnterPage1$txtTradeName" -> "福州",
      "SSDJNCREnterPage1$txtCheckCode" -> "4T268",
      "SSDJNCSLHAEnterPage1$txtEntRegNO" -> "",
      "SSDJNCSLHAEnterPage1$txtEntName" -> "",
      "SSDJNCAEnterPage1$txtNameRegNO" -> "",
      "SSDJNCAEnterPage1$txtEntName" -> "",
      "SSDJNCCEnterPage1$txtNameRegNO" -> "",
      "SSDJNCCEnterPage1$txtEntName" -> "",
      "SSDJNCREnterPage1$btnOnlyTradeName" -> "字号查重",
      "smObj" -> "SSDJNCREnterPage1$upTopBtn|SSDJNCREnterPage1$btnOnlyTradeName"
    )

    val cookie = "COLLCK=1125783080; COLLPCK=1125783080; COLLPCK=1125869560; ASP.NET_SessionId=yyhps1yeyvlpuw45znrt4z3p"
    val header = Map(HttpHandlerField.REFERER -> "http://app02.szaic.gov.cn/WERMIS2.WebUI/WebPages/Name/SSDJEnterPage.aspx",
    HttpHandlerField.COOKIE -> cookie)
    val result = HttpUtils.postText(
         "http://app02.szaic.gov.cn/WERMIS2.WebUI/WebPages/Name/SSDJEnterPage.aspx",
          params, Charset.forName("UTF-8"), header, true)
    println(result._3)

  }

  def getNowDate = {
    val sdf=new SimpleDateFormat("yyyyMMddHHmmssSS")
    val a = new Date()
    sdf.format(a);
  }
}
